using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using ProxyServer.Entities;
using ProxyServer.EntityFrameworkCore.ValueConverts;

namespace ProxyServer.EntityFrameworkCore.Sqlite;

public class ServiceEntityTypeConfiguration : IEntityTypeConfiguration<ServiceEntity>
{
    public void Configure(EntityTypeBuilder<ServiceEntity> builder)
    {
        builder.HasKey(x => x.Id);
        builder.HasIndex(x => x.Name).IsUnique();
        builder.Property(x => x.Created).HasConversion(DateTimeOffsetToTicksValueConverter.Singleton);
        builder.Property(x => x.LastModified).HasConversion(DateTimeOffsetToTicksValueConverter.Singleton);
        builder.Property(x => x.Endpoints).HasConversion(new JsonStringValueConverter<List<ServiceEndpointEntity>>([]));
    }
}